home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Networking / OT PAPServerSample / ATalkSampleUtils.c next >
Encoding:
C/C++ Source or Header  |  1998-02-06  |  4.7 KB  |  204 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        AtalkSampleUtils.cp
  3.  
  4.     Contains:    Some utility routines used by the AppleTalk sample programs
  5.  
  6.     Copyright:    © 1993-1995 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #ifndef __ATALKSAMPLEUTILS__
  11. #include "ATalkSampleUtils.h"
  12. #endif
  13. #ifndef __OPENTPTAPPLETALK__
  14. #include "OpenTptAppleTalk.h"
  15. #endif
  16. #include <Menus.h>
  17. #include <Devices.h>
  18. #include <Events.h>
  19. #ifndef __STDIO__
  20. #include <stdio.h>
  21. #endif
  22.  
  23. /*******************************************************************************
  24. ** ShowEndpointInfo
  25. **
  26. ********************************************************************************/
  27.  
  28.     static void ShowSize(char* format, SInt32 size)
  29.     {
  30.         if ( size == T_INFINITE )
  31.             fprintf(stderr, "%sT_INFINITE\n", format);
  32.         else if ( size == T_INVALID )
  33.             fprintf(stderr, "%sT_INVALID\n", format);
  34.         else
  35.             fprintf(stderr, "%s%ld\n", format, size);
  36.     }
  37.     
  38. void ShowEndpointInfo(EndpointRef ep)
  39. {
  40.     TEndpointInfo     info;
  41.     OSStatus        err;
  42.     SInt32             flags;
  43.     char*            type;
  44.     Boolean         ndComma;
  45.     
  46.     err = OTGetEndpointInfo(ep, &info);
  47.     fprintf(stderr, " TEndpointInfo:\n");
  48.     if ( err != kOTNoError )
  49.     {
  50.         fprintf(stderr, "     ERROR! = %d\n", err);
  51.     }
  52.     else
  53.     {
  54.         ShowSize("       addr = ", info.addr);
  55.         ShowSize("    options = ", info.options);
  56.         ShowSize("       tsdu = ", info.tsdu);
  57.         ShowSize("      etsdu = ", info.etsdu);
  58.         ShowSize("    connect = ", info.connect);
  59.         ShowSize("     discon = ", info.discon);
  60.         
  61.         fprintf(stderr, "   servtype = ");
  62.         switch ( info.servtype )
  63.         {
  64.             case T_COTS:        type = "T_COTS"; break;
  65.             case T_COTS_ORD:    type = "T_COTS_ORD"; break;
  66.             case T_CLTS:        type = "T_CLTS"; break;
  67.             case T_TRANS:        type = "T_TRANS"; break;
  68.             case T_TRANS_ORD:    type = "T_TRANS_ORD"; break;
  69.             case T_TRANS_CLTS:    type = "T_TRANS_CLTS"; break;
  70.             default:            type = NULL;
  71.         }
  72.         if ( type != NULL )
  73.             fprintf(stderr, "%s\n", type);
  74.         else
  75.             fprintf(stderr, "%lu\n", info.servtype);
  76.             
  77.         flags = info.flags;
  78.         fprintf(stderr, "      flags = ", info.flags);
  79.         ndComma = false;
  80.         if ( flags & T_SENDZERO )
  81.         {
  82.             flags &= ~T_SENDZERO;
  83.             fprintf(stderr, "T_SENDZERO");
  84.             ndComma = true;
  85.         }
  86.         if ( flags & T_XPG4_1 )
  87.         {
  88.             flags &= ~T_XPG4_1;
  89.             if ( ndComma )
  90.                 fprintf(stderr, ", ");
  91.             ndComma = true;
  92.             fprintf(stderr, "T_XPG4_1");
  93.         }
  94.         if ( flags & T_CAN_RESOLVE_ADDR )
  95.         {
  96.             flags &= ~T_CAN_RESOLVE_ADDR;
  97.             if ( ndComma )
  98.                 fprintf(stderr, ", ");
  99.             ndComma = true;
  100.             fprintf(stderr, "T_CAN_RESOLVE_ADDR");
  101.         }
  102.         if ( flags & T_CAN_SUPPLY_MIB )
  103.         {
  104.             flags &= ~T_CAN_SUPPLY_MIB;
  105.             if ( ndComma )
  106.                 fprintf(stderr, ", ");
  107.             ndComma = true;
  108.             fprintf(stderr, "T_CAN_SUPPLY_MIB");
  109.         }
  110.         if ( flags != 0 )
  111.         {
  112.             if ( ndComma )
  113.                 fprintf(stderr, ", ");
  114.             fprintf(stderr, "%08lX", flags);
  115.             
  116.         }
  117.         fprintf(stderr, "\n");
  118.     }
  119. }
  120.  
  121. /*******************************************************************************
  122. ** ShowEndpointState
  123. ********************************************************************************/
  124.  
  125. void ShowEndpointState(EndpointRef ep, char* prefixString)
  126. {
  127.     char*     strPtr;
  128.     OTResult     state;
  129.     
  130.     state = OTGetEndpointState(ep);
  131.     
  132.     fprintf(stderr, "%sState = %d, ", prefixString, state);
  133.     switch ( state )
  134.     {
  135.         case T_UNINIT:
  136.             strPtr = "T_UNINIT";
  137.             break;
  138.         case T_UNBND:
  139.             strPtr = "T_UNBND";
  140.             break;
  141.         case T_IDLE:
  142.             strPtr = "T_IDLE";
  143.             break;
  144.         case T_OUTCON:
  145.             strPtr = "T_OUTCON";
  146.             break;
  147.         case T_INCON:
  148.             strPtr = "T_INCON";
  149.             break;
  150.         case T_DATAXFER:
  151.             strPtr = "T_DATAXFER";
  152.             break;
  153.         case T_OUTREL:
  154.             strPtr = "T_OUTREL";
  155.             break;
  156.         case T_INREL:
  157.             strPtr = "T_INREL";
  158.             break;
  159. //        case T_INFLUX:
  160. //            strPtr = "T_INFLUX";
  161. //            break;
  162.         default:
  163.             strPtr = "Unknown";
  164.     }
  165.     fprintf(stderr,"%s\n", strPtr);
  166. }
  167.  
  168. /*******************************************************************************
  169. ** ShowFullEndpointData
  170. **
  171. ********************************************************************************/
  172.  
  173. void ShowFullEndpointData(EndpointRef ep)
  174. {
  175.     fprintf(stderr, "FULL ENDPOINT INFO FOR ENDPOINT AT %08lX\n", ep);
  176.     
  177.     fprintf(stderr, "               Mode = %s\n", (OTIsSynchronous(ep) ? "Synchronous" : "Asynchronous"));
  178.  
  179.     ShowEndpointState(ep, "              ");
  180.     
  181.     fprintf(stderr, "             Look() = %d\n", OTLook(ep));
  182.     
  183.     ShowEndpointInfo(ep);
  184.     
  185.     fprintf(stderr, "");
  186. }
  187.  
  188. /*******************************************************************************
  189. ** ShowDDPAddress -- print out an AppleTalk DDP address
  190. ********************************************************************************/
  191.  
  192. void ShowDDPAddress(DDPAddress* addr)
  193. {
  194.     if (addr->fAddressType == AF_ATALK_DDP ||
  195.         addr->fAddressType == AF_ATALK_DDPNBP)
  196.     {
  197.         fprintf(stderr, "Net $%04X, Node $%02X, Socket $%02X, Type $%02X",
  198.             addr->fNetwork, addr->fNodeID, addr->fSocket, addr->fDDPType);
  199.     }
  200.     else
  201.         fprintf(stderr, "Not DDP Addr!");
  202. }
  203.  
  204.